package Review2;

public class Test15 {
	public static void main(String[] args) {
		ListNode head = new ListNode(1);
        /*ListNode p1 = new ListNode(2);
        ListNode p2 = new ListNode(3);
        ListNode p3 = new ListNode(4);
        head.next = p1;
        p1.next = p2;
        p2.next = p3;*/
		ListNode result = findKReversely(head, 1);
		if (result != null){
			System.out.println(result.value);
		} else {
			System.out.println(result);
		}
	}
    public static ListNode findKReversely(ListNode head,int k){
    	ListNode p = head;
    
    	ListNode p1 = head;
    	for(int i =1;i<=k-1;i++){
    		if(p1.next!=null){
    			p1=p1.next;
    		}
    		else{
    			return null;
    		}
    		
    	}
    	ListNode p2 = head;
    	while(p1.next!=null){
    		p1=p1.next;
    		p2=p2.next;
    	}
    	return p2;
    }
}
